package com.example.workermanage

import android.content.Context
import android.content.SharedPreferences
import android.util.Log
import androidx.work.Data
import androidx.work.Worker
import androidx.work.WorkerParameters
import androidx.work.workDataOf

class MyWorker(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) {
    override fun doWork(): Result {
        val name: String? = inputData.getString(INPUT_DATA_KEY)
        val TAG = "LOG"
//        Log.d(TAG, "doWork: $name start")
        Thread.sleep(3000)
        val sp: SharedPreferences = applicationContext.getSharedPreferences(SHARED_PREFERENCE_NAME,Context.MODE_PRIVATE)
        var number:Int =sp.getInt(name,0)
        sp.edit().putInt(name,++number).apply()

//        Log.d(TAG, "doWork: $name end")
        return Result.success(workDataOf(OUTPUT_DATA_KEY to "$name output"))
    }
}